all repos — caroster @ 8b3a718187d3e9765687e3a91de927242e423fbc

[Octree] Group carpool to your event https://caroster.io

frontend/pages/e/[uuid]/options.tsx (view raw)

 1import Box from '@mui/material/Box';
 2import Container from '@mui/material/Container';
 3import {useTheme} from '@mui/material/styles';
 4import {PropsWithChildren} from 'react';
 5import pageUtils from '../../../lib/pageUtils';
 6import useEventStore from '../../../stores/useEventStore';
 7import EventLayout, {TabComponent} from '../../../layouts/Event';
 8import {EventByUuidDocument} from '../../../generated/graphql';
 9import CarosterPlusSettings from '../../../containers/CarosterPlusSettings';
10import {getLocaleForLang} from '../../../lib/getLocale';
11
12interface Props {
13  eventUUID: string;
14  announcement?: string;
15}
16
17const Page = (props: PropsWithChildren<Props>) => {
18  return <EventLayout {...props} Tab={OptionsTab} />;
19};
20
21const OptionsTab: TabComponent<Props> = () => {
22  const theme = useTheme();
23  const event = useEventStore(s => s.event);
24
25  if (!event) return null;
26
27  return (
28    <Box position="relative">
29      <Container
30        sx={{
31          p: 4,
32          mt: 6,
33          mb: 11,
34          mx: 0,
35          [theme.breakpoints.down('md')]: {
36            p: 2,
37            mt: 13,
38          },
39        }}
40      >
41        <CarosterPlusSettings event={event} />
42      </Container>
43    </Box>
44  );
45};
46
47export const getServerSideProps = pageUtils.getServerSideProps(
48  async (context, apolloClient) => {
49    const {uuid} = context.query;
50    const {host = ''} = context.req.headers;
51    let event = null;
52
53    // Fetch event
54    try {
55      const {data} = await apolloClient.query({
56        query: EventByUuidDocument,
57        variables: {uuid},
58      });
59      event = data?.eventByUUID?.data;
60    } catch (error) {
61      return {
62        notFound: true,
63      };
64    }
65
66    const carosterPlusActivated =
67      event?.attributes?.enabled_modules?.includes('caroster-plus');
68
69    if (!carosterPlusActivated)
70      return {
71        redirect: {
72          destination: `/e/${uuid}/prices`,
73          permanent: false,
74        },
75      };
76
77    const description = await getLocaleForLang(
78      event?.attributes?.lang,
79      'meta.description'
80    );
81
82    return {
83      props: {
84        eventUUID: uuid,
85        metas: {
86          title: event?.attributes?.name || '',
87          description,
88          url: `https://${host}${context.resolvedUrl}`,
89        },
90      },
91    };
92  }
93);
94export default Page;